package com.qupai.controller.user;


import com.qupai.dto.CancelRegistrationDTO;
import com.qupai.dto.RegistrationDTO;
import com.qupai.entity.Registration;
import com.qupai.result.PageResult;
import com.qupai.result.Result;
import com.qupai.service.IRegistrationService;
import com.qupai.vo.CertificateVO;
import com.qupai.vo.RegistrationVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 活动报名表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-03-17
 */
@RestController("userRegistrationController")
@RequestMapping("/user/registration")
@Slf4j
@Tag(name = "志愿-C端-活动报名接口")
@RequiredArgsConstructor
public class RegistrationController {

    private final IRegistrationService iRegistrationService;

    @PostMapping("/signUp")
    @Operation(summary = "报名活动")
    public Result<CertificateVO> add(@RequestBody RegistrationDTO registrationDTO){
        log.info("报名活动：{}",registrationDTO);
        CertificateVO certificateVO= iRegistrationService.signUp(registrationDTO);
        return Result.success(certificateVO);
    }

    @DeleteMapping("/cancel")
    @Operation(summary = "取消报名活动")
    public Result<String> cancel(@RequestBody CancelRegistrationDTO cancelRegistrationDTO){
        log.info("取消报名活动：{}",cancelRegistrationDTO);
        iRegistrationService.cancel(cancelRegistrationDTO);
        return Result.success();
    }

    /**
     * 历史报名查询
     *
     * @param page 页码
     * @param pageSize 每页数量
     * @param status  报名状态：1、已报名 2、已取消 3、已通过 4、已拒绝
     * @return 返回数据
     */
    @GetMapping("/historyRegistration")
    @Operation(summary = "历史报名查询")
    public Result<PageResult> page(Long page, Long pageSize, Integer status) {
        PageResult pageResult = iRegistrationService.pageQueryUser(page, pageSize, status);
        return Result.success(pageResult);
    }

    @GetMapping("/RegistrationDetail/{registrationId}")
    @Operation(summary = "查询报名详情")
    public Result<RegistrationVO> details(@PathVariable("registrationId") Long registrationId) {
        Registration registration = iRegistrationService.getById(registrationId);
        RegistrationVO registrationVO=new RegistrationVO();
        BeanUtils.copyProperties(registration, registrationVO);
        return Result.success(registrationVO);
    }

}
